package com.itheima.service.imol;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.aoon.Log;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

//员工业务实现类
@Slf4j
@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page,pageSize);

        List<Emp> empList=empMapper.page(name,gender,begin,end);

        Page<Emp> p=(Page<Emp>) empList;

        PageBean pageBean =new PageBean(p.getTotal(),p.getResult());

        return pageBean;
    }

    @Log
    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }


    @Log
    @Override
    public void insert(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }


    @Override
    public Emp getById(Integer id) {
        return empMapper.findById(id);
    }

    @Log
    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now()); //更新修改时间为当前时间

        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
        Emp ligunEmp=empMapper.login(emp);
        return   ligunEmp;
    }

    @Log
    @Override
    public void deleteByDeptid(Integer id) {
        empMapper.deleteByDeptId(id);
    }




   /* @Override
    public PageBean page(Integer page, Integer pageSize) {
        Long count = empMapper.count();

        //2、获取分页查询结果列表
        Integer start = (page - 1) * pageSize; //计算起始索引 , 公式: (页码-1)*页大小
        List<Emp> empList = empMapper.list(start, pageSize);

        //3、封装PageBean对象
        PageBean pageBean = new PageBean(count , empList);
        return pageBean;
    }*/

}